package api

import (
	"api/basic/config"
	__ "api/basic/proto"
	"api/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func LabelAdd(c *gin.Context) {
	var form request.Label
	// 根据 Content-Type Header 推断使用哪个绑定器。
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	add, err := config.Client.LabelAdd(c, &__.LabelAddReq{
		Address: form.Address,
		Subject: form.Subject,
		Att:     form.Att,
	})
	if err != nil {
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"data": add,
	})
}
